
//
//  ZTNextSiginController.m
//  ZTTaxSecond
//
//  Created by Zhengtong on 15/11/17.
//  Copyright © 2015年 Zhengtong. All rights reserved.
//

#import "ZTNextSiginController.h"

#import "NSObject+ToolObject.h"

#import "ZTTabBarController.h"
@interface ZTNextSiginController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollerView;
//企业名称
@property (weak, nonatomic) IBOutlet UITextField *enertiseTextField;
//一户式
@property (weak, nonatomic) IBOutlet UITextField *searchTextField;
//法人
@property (weak, nonatomic) IBOutlet UITextField *enertisePersonTextField;
//证件号码
@property (weak, nonatomic) IBOutlet UITextField *DocumentNumTextField;

@property (weak, nonatomic) IBOutlet UIImageView *topImageView;
- (IBAction)agreeAndDisagreeClick:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;
@property (weak, nonatomic) IBOutlet UIButton *disAgreeBtn;
- (IBAction)finishBtnClick:(UIButton *)sender;
@end

@implementation ZTNextSiginController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"填写确认身份信息";
    
    self.scrollerView.contentSize = CGSizeMake(DEVICE_WIDTH, 0);
    [self setUpNavgationBar];
    
    
    self.agreeBtn.hidden = YES;
    self.disAgreeBtn.hidden = NO;
}

#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
     self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    //导航条背景图片
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"上栏"] forBarMetrics:UIBarMetricsDefault];
    //导航标题颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 10, 16);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"返回按钮"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //rightItem
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 50, 20);
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)viewWillLayoutSubviews
{
    self.topImageView.frame = CGRectMake((DEVICE_WIDTH-258)/2, 20, 258, 41);
    [self.topImageView setNeedsDisplay];
}

- (void)leftBtnClick
{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)rightBtnClick:(UIButton *)btn
{
   [self nextLoadData];
}
- (IBAction)finishBtnClick:(UIButton *)sender {
    [self nextLoadData];
}

- (void)nextLoadData
{
    if (![self judgmentIsEmpty:self.enertiseTextField.text]) {
        [self showHUD:@"纳税人代码不能为空"];
    }else if (![self judgmentIsEmpty:self.searchTextField.text]){
        [self showHUD:@"密码不能为空"];
    }else if (![self judgmentIsEmpty:self.enertisePersonTextField.text]){
        [self showHUD:@"确认密码不能为空"];
    }else if (![self judgmentIsEmpty:self.DocumentNumTextField.text]){
        [self showHUD:@"证件号码不能为空"];
    }else if (!self.agreeBtn.hidden){
        [self showHUD:@"请同意协议"];
    }else{
        NSDictionary *dict = @{@"taxpayerOrgId" :self.enertiseTextField.text,@"taxpayerId":self.searchTextField.text,@"jurpName":self.enertisePersonTextField.text,@"jurpId":self.DocumentNumTextField.text};
        
        [RequestTool requestSiginUserId:self.useId withUserPwd:self.psw withParams:dict WithBlock:^(id result, NSString *error) {
            if (error == nil) {
                NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                [userDefault setObject:@"YES" forKey:FIRSTLOGIN];
                [userDefault synchronize];
                UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
                ZTTabBarController *tab = [[ZTTabBarController alloc] init];
                window.rootViewController = tab;
            }else{
                [self showHUD:error];
            }
        }];
    }
    
    
}

- (IBAction)agreeAndDisagreeClick:(UIButton *)sender {
    if (sender.tag == 1) {
        self.agreeBtn.hidden = YES;
        self.disAgreeBtn.hidden = NO;
    }else{
        self.agreeBtn.hidden = NO;
        self.disAgreeBtn.hidden = YES;
    }
}
@end
